package com.demo.shiro.service.impl;

import com.demo.shiro.mapper.UserInfoMapper;
import com.demo.shiro.model.UserInfo;
import com.demo.shiro.service.UserInfoService;
import com.demo.shiro.utils.MD5Utils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author Jmy
 * @date 2019/7/26 19:16
 * @email jiaomingyu5778@gmail.com
 */
@Repository("UserInfoService")
public class UserInfoServiceImpl extends BaseService<UserInfo> implements UserInfoService {

    @Autowired
    private UserInfoMapper userInfoMapper;

    @Override
    public int inset(UserInfo userInfo) {
        if (userInfo == null) {
            return 0;
        }
        UserInfo oldUser = userInfoMapper.findByUserName(userInfo.getUsername());
        if (oldUser != null) {
            return -1;
        }
        userInfo.setStatus("1");
        userInfo.setPassword(MD5Utils.encrypt(userInfo.getUsername(), userInfo.getPassword()));
        return userInfoMapper.insert(userInfo);
    }


    @Override
    public UserInfo findByUserName(String userName) {
        return userInfoMapper.findByUserName(userName);
    }
}
